package com.soft.servlet;


import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AdminLoginServlet", urlPatterns = "/AdminLogin")
public class AdminLoginServlet extends HttpServlet {

    private Domain domain;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setCharacterEncoding("GBK");

        domain = new Domain();

        String account = request.getParameter("shopManager.manager");
        String pwd = request.getParameter("shopManager.password");

        if(domain.AdminLogin(account, pwd)) {
            request.getSession().setAttribute("adminName", account);
            request.getSession().setAttribute("flag", 3);
            request.getRequestDispatcher("/GoodsList").forward(request, response);
        } else {
            request.getSession().setAttribute("flag", 4);
            response.sendRedirect("/manage1.jsp");
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request,response);
    }

}
